//
//  MyPetTableViewCell.m
//  chongwu
//
//  Created by 隼目 on 2021/9/17.
//

#import "MyPetTableViewCell.h"

@implementation MyPetTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)creatView{
    self.backgroundColor=[UIColor clearColor];
    
    UIView *centerView=[UIView new];
    [self.contentView addSubview:centerView];
    [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*_mainWidth);
        make.right.mas_equalTo(-30*_mainWidth);
        make.top.mas_equalTo(10*_mainHeight);
        make.bottom.mas_equalTo(-10*_mainHeight);
    }];
    centerView.backgroundColor=[UIColor whiteColor];
    centerView.layer.cornerRadius=25*_mainWidth;
    
    UIView *xianView=[UIView new];
    [centerView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*_mainWidth);
        make.right.mas_offset(-30*_mainWidth);
        make.height.mas_equalTo(2*_mainHeight);
        make.bottom.mas_equalTo(-87*_mainWidth);
    }];
    xianView.backgroundColor=rgba(232,232,232,1);
    
    UIView *topView=[UIView new];
    [centerView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.bottom.mas_equalTo(xianView.mas_top);
    }];
    
    UIImageView *petImage=[UIImageView new];
    [topView addSubview:petImage];
    [petImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(21*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.width.height.mas_equalTo(141*_mainWidth);
    }];
    petImage.layer.masksToBounds=YES;
    petImage.layer.cornerRadius=141*_mainWidth/2;
    [petImage sd_setImageWithURL:nil placeholderImage:[UIImage imageNamed:@"gou"]];
    
    UILabel *nameLabel=[UILabel new];
    [topView addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(petImage.mas_right).mas_equalTo(15*_mainWidth);
        make.top.mas_equalTo(52*_mainHeight);
        make.right.mas_equalTo(90*_mainWidth);
    }];
    nameLabel.text=@"狗【富贵】";
    nameLabel.textColor=rgba(47,47,47,1);
    nameLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(36)];
    
    UILabel *label2=[UILabel new];
    [topView addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(nameLabel);
        make.bottom.mas_equalTo(-35*_mainHeight);
    }];
    [label2 layoutIfNeeded];
    label2.text=@"大型";
    label2.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(25)];
    label2.textColor=rgba(102,102,102,1);
    
    UIView *dogXian2=[UIView new];
    [topView addSubview:dogXian2];
    [dogXian2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(label2.mas_right).mas_equalTo(10*_mainWidth);
        make.centerY.mas_equalTo(label2);
        make.width.mas_equalTo(2*_mainWidth);
        make.height.mas_equalTo(23*_mainHeight);
    }];
    dogXian2.backgroundColor=rgba(151,151,151,1);
    
    UILabel *label3=[UILabel new];
    [topView addSubview:label3];
    [label3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(dogXian2.mas_right).mas_equalTo(10*_mainWidth);
        make.centerY.mas_equalTo(label2);
    }];
    [label3 layoutIfNeeded];
    label3.text=@"3～4kg";
    label3.font=label2.font;
    label3.textColor=label2.textColor;
    
    UIView *dogXian3=[UIView new];
    [topView addSubview:dogXian3];
    [dogXian3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(label3.mas_right).mas_equalTo(10*_mainWidth);
        make.centerY.mas_equalTo(label2);
        make.width.mas_equalTo(2*_mainWidth);
        make.height.mas_equalTo(23*_mainHeight);
    }];
    dogXian3.backgroundColor=rgba(151,151,151,1);

    UILabel *label4=[UILabel new];
    [topView addSubview:label4];
    [label4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(dogXian3.mas_right).mas_equalTo(10*_mainWidth);
        make.centerY.mas_equalTo(label2);
    }];
    [label4 layoutIfNeeded];
    label4.text=@"无过往病例";
    label4.font=label2.font;
    label4.textColor=label2.textColor;
    
    UIButton *selectBtn=[UIButton new];
    [topView addSubview:selectBtn];
    [selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-33*_mainWidth);
        make.top.mas_equalTo(35*_mainHeight);
        make.width.height.mas_equalTo(37*_mainWidth);
    }];
    selectBtn.tag=self.tag;
    if (self.isSelected) {
        [selectBtn setImage:[UIImage imageNamed:@"xuanzhong-1" ] forState:0];
    }else{
        [selectBtn setImage:[UIImage imageNamed:@"weixuanzhong-1" ] forState:0];
    }
    
    [selectBtn addTarget:self action:@selector(selectCellBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *bottomView=[UIView new];
    [centerView addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(xianView.mas_bottom);
    }];
    
    BaseButton *rightBtn=[BaseButton new];
    [bottomView addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-31*_mainHeight);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(50*_mainHeight);
        make.width.mas_equalTo(110*_mainWidth);
    }];
    rightBtn.leftOrRightOrTopOrDown=1;
    rightBtn.btnAlignment=NSTextAlignmentRight;
    rightBtn.width=11;
    [rightBtn setImage:[UIImage imageNamed:@"shanchu-1"] forState:0];
    [rightBtn setTitle:@"删除" forState:0];
    [rightBtn setTitleColor:rgba(102,102,102,1) forState:0];
    rightBtn.titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(25)];
    
    BaseButton *leftBtn=[BaseButton new];
    [bottomView addSubview:leftBtn];
    [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(rightBtn.mas_left).mas_equalTo(-36*_mainHeight);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(50*_mainHeight);
        make.width.mas_equalTo(110*_mainWidth);
    }];
    leftBtn.leftOrRightOrTopOrDown=1;
    leftBtn.btnAlignment=NSTextAlignmentRight;
    leftBtn.width=11;
    [leftBtn setImage:[UIImage imageNamed:@"bianji"] forState:0];
    [leftBtn setTitle:@"编辑" forState:0];
    [leftBtn setTitleColor:rgba(102,102,102,1) forState:0];
    leftBtn.titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(25)];
}

-(void)creatBtnView{
    self.backgroundColor=[UIColor clearColor];
    
    UIButton *signInBtn=[UIButton new];
    [self.contentView addSubview:signInBtn];
    [signInBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(39*_mainWidth);
        make.width.mas_equalTo(_mainW-78*_mainWidth);
        make.centerY.mas_equalTo(0);
        make.height.mas_equalTo(_mainHeight*87);
    }];
    [signInBtn setTitle:@"确定" forState:0];
    [signInBtn setTitleColor:[UIColor whiteColor] forState:0];
    signInBtn.titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(36)];
    
    [signInBtn layoutIfNeeded];
    signInBtn.layer.masksToBounds=YES;
    signInBtn.layer.cornerRadius=87*_mainHeight/2;
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = signInBtn.bounds;
    //将CAGradientlayer对象添加在我们要设置背景色的视图的layer层
    [signInBtn.layer insertSublayer:gradientLayer atIndex:0];
    //设置渐变区域的起始和终止位置（范围为0-1）
    gradientLayer.startPoint = CGPointMake(0, 1);
    gradientLayer.endPoint = CGPointMake(1, 1);
    gradientLayer.colors = @[(__bridge id)rgba(255,159,0,1).CGColor,
                             (__bridge id)rgba(255,116,0,1).CGColor ,
                             (__bridge id)rgba(255,102,0,1).CGColor];
    //设置颜色分割点（范围：0-1）
    gradientLayer.locations = @[@(0),@(0.5), @(1.0f)];
    signInBtn.layer.shadowColor = rgba(196,50,0,0.36).CGColor;
    signInBtn.layer.shadowOffset = CGSizeMake(0,0);
    signInBtn.layer.shadowOpacity = 1;
    signInBtn.layer.shadowRadius = 4;
}


-(void)selectCellBtn:(UIButton *)btn{
    if (self.delegate!=nil) {
        [self.delegate selectCell:btn.tag];
    }
}

@end
